//
//  ScheduleViewController.m
//  Translation
//
//  Created by mac on 17/6/6.
//  Copyright © 2017年 Mephsito. All rights reserved.
//

#import "ScheduleViewController.h"
#import "ScheduleViewModel.h"


@interface ScheduleViewController ()
@property (nonatomic, strong)ScheduleViewModel *viewModel;

@end

@implementation ScheduleViewController
@dynamic viewModel;

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.backgroundColor=ColorBG;
    self.tableView.rowHeight=210;
    
    CGFloat btnW=40.0f;
    CGFloat space=15.0f;
    CGFloat count=4;
    
    CGFloat viewW=(btnW+space)*count+space;
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(50, 150, viewW, btnW)];
    view.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:view];
    
    for (int i=0; i<count; i++) {
        CGFloat btnX=space+(btnW+space)*i;
        UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(btnX, 0, btnW, btnW)];
        [btn setBackgroundColor:[UIColor randomFlatColor]];
        [view addSubview:btn];
    }
    
    [self setupAutoMarginViewsWithCount:4 itemWidth:btnW];
    
}


// 设置一排固定宽度自动间距子view
- (void)setupAutoMarginViewsWithCount:(NSInteger)count itemWidth:(CGFloat)itemWidth
{
    UIView *contentView = [UIView new];
    contentView.backgroundColor = [UIColor blueColor];
    [self.view addSubview:contentView];
    
    NSMutableArray *temp = [NSMutableArray new];
    for (int i = 0; i < count; i++) {
        UIButton *view = [UIButton new];
        view.backgroundColor = [UIColor randomFlatColor];
        [contentView addSubview:view];
        view.sd_layout.autoHeightRatio(1); // 设置高度约束
        [temp addObject:view];
    }
    
    // 此步设置之后_autoMarginViewsContainer的高度可以根据子view自适应
    [contentView setupAutoMarginFlowItems:[temp copy]
                                   withPerRowItemsCount:count
                                              itemWidth:itemWidth
                                         verticalMargin:10
                                      verticalEdgeInset:4
                                    horizontalEdgeInset:10];
    
    contentView.sd_layout
    .leftSpaceToView(self.view, 10)
    .rightSpaceToView(self.view, 10)
    .topSpaceToView(contentView, 10);
    
}

- (void)bindViewModel{
    [super bindViewModel];
}




@end
